﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using IKEA.FileExchange.Domain.StringResources;

namespace IKEA.FileExchange.Domain.FilePackage
{
    public class FilePackageValidationResult
    {
        private List<string> errors;

        private ReadOnlyCollection<string> errorsReadonly;

        public ReadOnlyCollection<string> Errors
        {
            get
            {
                return errorsReadonly;
            }
        }

        public FilePackageValidationResult()
        {
            errors = new List<string>();
            errorsReadonly = new ReadOnlyCollection<string>(errors);
        }

        internal void AddError(string error)
        {
            errors.Add(error);
        }
    }

    public static class FilePackageValidationHelper
    {
        public static FilePackageValidationResult ValidateFilePackage(FilePackageInformation filePackage)
        {
            if (filePackage == null)
            {
                throw new ArgumentNullException("filePackage");
            }

            if (filePackage.IsConfidential)
            {
                    
            }

            return null;
        }

        private static bool ValidateEmail(string email)
        {
            return true;
        }

        private static bool CheckRecipients(FilePackageInformation filePackage, FilePackageValidationResult validationResult)
        {
            bool ok = false;

            if (filePackage == null)
            {
                throw new ArgumentNullException("filePackage");
            }

            if (validationResult == null)
            {
                throw new ArgumentNullException("validationResult");
            }

            if (!string.IsNullOrEmpty(filePackage.RecipientsRaw))
            {
                string[] addresses = filePackage.RecipientsRaw.Split(';');

                if (addresses.Length == 0)
                {
                    validationResult.AddError(UIStrings.FPVE_RECIPIENTS_REQUIRED);
                }
                else
                {
                    foreach (string address in addresses)
                    {
                        string invalidAdressErrorMsg = string.Format(UIStrings.FPVE_INVALID_EMAIL,address);
                        validationResult.AddError(invalidAdressErrorMsg);
                    }
                }
            }
            else
            {
                validationResult.AddError(UIStrings.FPVE_RECIPIENTS_REQUIRED);
            }

            return ok;
        }
    }
}
